package com.imy.lua.lib.environment;

import android.content.Context;
import android.os.Environment;

import androidx.annotation.NonNull;

import com.immomo.mls.LuaViewManager;
import com.immomo.mls.annotation.LuaBridge;
import com.immomo.mls.annotation.LuaClass;
import com.immomo.mls.wrapper.callback.IVoidCallback;

import org.luaj.vm2.Globals;
import org.luaj.vm2.LuaValue;

/**
 * Created by MLN Template
 * 注册方法：
 * Register.newSHolderWithLuaClass(UDEnvironment.LUA_CLASS_NAME, UDEnvironment.class)
 */
@LuaClass(isStatic = true)
public class UDEnvironment {
    /**
     * Lua类名
     */
    public static final String LUA_CLASS_NAME = "Environment";

    //<editor-fold desc="Bridge API">

    /**
     * 直接在属性中增加注解，可让Lua有相关属性
     * eg:
     * Environment:property()      --获取相关值
     * Environment:property(10)    --设置相关值
     */

    @LuaBridge
    public static String getPath() {
        return Environment.getExternalStorageDirectory().getAbsolutePath();
    }

    //</editor-fold>

    /**
     * 获取上下文，一般情况，此上下文为Activity
     *
     * @param globals 虚拟机，可通过构造函数存储
     */
    protected static Context getContext(@NonNull Globals globals) {
        LuaViewManager m = (LuaViewManager) globals.getJavaUserdata();
        return m != null ? m.context : null;
    }
}
